package com.lkei.controller;

import com.alibaba.fastjson.JSONObject;
import com.lkei.dto.Result;
import com.lkei.entity.SchoolTeacherMessage;
import com.lkei.service.SchoolTeacherMessageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("schoolTeacherMessage")
public class SchoolTeacherMessageController {
    @Autowired
    private SchoolTeacherMessageService schoolTeacherMessageService;

    @CrossOrigin
    @RequestMapping("findTaskList")
    public Result findTaskList(@RequestBody String data){
        // 将接收到的Json解析为map
        JSONObject jsonObject = JSONObject.parseObject(data);
        Map<String, Object> map = new HashMap<>();
        map.putAll(jsonObject);
        int teacherID = Integer.valueOf(map.get("account").toString()).intValue();
        List<SchoolTeacherMessage> taskList = schoolTeacherMessageService.findTaskList(teacherID);
        return Result.SUCCESS.setNewData(taskList);
    }

    @CrossOrigin
    @RequestMapping("findNoticeList")
    public Result findNoticeList(@RequestBody String data){
        // 将接收到的Json解析为map
        JSONObject jsonObject = JSONObject.parseObject(data);
        Map<String, Object> map = new HashMap<>();
        map.putAll(jsonObject);
        int teacherID = Integer.valueOf(map.get("account").toString()).intValue();
        List<SchoolTeacherMessage> noticeList = schoolTeacherMessageService.findNoticeList(teacherID);
        return Result.SUCCESS.setNewData(noticeList);
    }
}
